package tree;

/**
 * @author : Rookie
 * @description :
 * @date : 2023/10/25
 */
public class MergeBinaryTree {

    public static void main(String[] args) {
        int[] input1 = new int[] {1,3,2,5,-1,-1,-1};
        int[] input2 = new int[] {2,1,3,-1,4,-1,7};
        TreeNode root1 = BinaryTreeUtil.buildTree(input1);
        TreeNode root2 = BinaryTreeUtil.buildTree(input2);
        TreeNode root = merge(root1, root2);
        BinaryTreeUtil.Traversal.sequenceTraversal(root);
    }

    private static TreeNode merge(TreeNode node1,TreeNode node2) {
        if (node1 == null) return node2;
        if (node2 == null) return node1;

        TreeNode node = new TreeNode(node1.element + node2.element);
        node.left = merge(node1.left,node2.left);
        node.right = merge(node1.right,node2.right);
        return node;
    }
}
